package store

import (
	"context"
	"enode/store/tiny_file"
	"github.com/google/uuid"
	"go.uber.org/zap"
	"io"
)

const (
	FilePermission = 0600
	DirPermission  = 0700
)

type Store interface {
	PutPiece(ctx context.Context, pieceId uuid.UUID, expire int, size int, r io.Reader, md5Sum [16]byte) (err error)
	GetPiece(ctx context.Context, key uuid.UUID) (data []byte, err error)
	DelPiece(ctx context.Context, key uuid.UUID) (err error)
	Mode() string
}

func NewStore(ctx context.Context, log *zap.Logger, mode, dataDir string) Store {
	store := tiny_file.NewFileStore(ctx, log, dataDir)
	go store.Run(ctx)
	return store
}
